﻿<phone:PhoneApplicationPage x:Class="MobiSms.Wasun.Views.MessageCollectionView"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:UX="clr-namespace:MobiSms.UX;assembly=MobiSms.UX"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                            xmlns:viewmodel="clr-namespace:MobiSms.ViewModel;assembly=MobiSms.ViewModel"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Orientation="Portrait"
                            SupportedOrientations="Portrait"
                            d:DesignHeight="800"
                            d:DesignWidth="480"
                            shell:SystemTray.IsVisible="False"
                            mc:Ignorable="d">

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="message_itemstyle" TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Button Margin="0,0,0,12"
                                Click="GotoDetailsView"
                                Tag="{Binding Guid}">
                            <Button.Style>
                                <Style TargetType="Button">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="Button">
                                                <Grid>
                                                    <Grid Background="White" Opacity="0"></Grid>
                                                    <StackPanel>
                                                        <StackPanel Orientation="Horizontal">
                                                            <Path Width="24"
                                                              Height="24"
                                                              Margin="12"
                                                              Data="M-150.204,626.126C-152.317,626.126 -154.429,626.126 -156.541,626.126 -167.642,633.42 -180.629,646.047 -189.668,657.238 -190.916,658.782 -192.945,662.362 -193.701,662.422 -194.041,662.448 -198.024,659.719 -198.614,659.297 -202.818,656.279 -205.779,653.709 -209.257,650.899 -211.248,652.172 -212.879,653.805 -214.153,655.797 -206.627,665.074 -200.283,675.534 -193.124,685.18 -181.491,665.11 -168.473,644.683 -152.796,629.006 -151.735,627.946 -149.817,626.933 -150.204,626.126z"
                                                              Fill="{StaticResource PhoneForegroundBrush}"
                                                              RenderTransformOrigin="0.5,0.5"
                                                              Stretch="Uniform"
                                                              Visibility="{Binding Status,
                                                                                   ConverterParameter=Succeed,
                                                                                   Converter={StaticResource ValueEqualsParameterToVisibilityConverter}}">
                                                                <Path.RenderTransform>
                                                                    <TransformGroup>
                                                                        <TransformGroup.Children>
                                                                            <RotateTransform Angle="0" />
                                                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                                                        </TransformGroup.Children>
                                                                    </TransformGroup>
                                                                </Path.RenderTransform>
                                                            </Path>
                                                            <Path Width="24"
                                                              Height="24"
                                                              Margin="12"
                                                              Data="M29.9314,44.295944L34.223,44.295944 34.223,48.586002 29.9314,48.586002z M29.749001,26.198L34.390999,26.198 34.390999,31.451971 33.290699,42.814522 30.8636,42.814522 29.749001,31.451971z M32,10.338882L8.2226601,54.42371 55.777302,54.42371z M32,0L48,29.665951 64,59.331001 32,59.331001 0,59.331001 16,29.665951z"
                                                              Fill="{StaticResource PhoneForegroundBrush}"
                                                              RenderTransformOrigin="0.5,0.5"
                                                              Stretch="Uniform"
                                                              Visibility="{Binding Status,
                                                                                   ConverterParameter=Faild,
                                                                                   Converter={StaticResource ValueEqualsParameterToVisibilityConverter}}">
                                                                <Path.RenderTransform>
                                                                    <TransformGroup>
                                                                        <TransformGroup.Children>
                                                                            <RotateTransform Angle="0" />
                                                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                                                        </TransformGroup.Children>
                                                                    </TransformGroup>
                                                                </Path.RenderTransform>
                                                            </Path>
                                                            <TextBlock Style="{StaticResource PhoneTextTitle2Style}" Text="{Binding SendId, Converter={StaticResource MessageSendIdConverter}}" />
                                                        </StackPanel>
                                                        <TextBlock Style="{StaticResource PhoneTextSubtleStyle}"
                                                               Text="{Binding DisplayContent}"
                                                               TextWrapping="Wrap" />
                                                    </StackPanel>
                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Button.Style>
                        </Button>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush ImageSource="{Binding GlobalSettings.BackgroundImage}" Stretch="{Binding GlobalSettings.BackgroundImageStretch}" />
        </Grid.Background>
        <Grid.DataContext>
            <viewmodel:MessageCollectionViewModel />
        </Grid.DataContext>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel"
                    Grid.Row="0"
                    Margin="12,17,0,28">
            <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Text="{StaticResource IDS_APP_NAME}" />
            <TextBlock Margin="9,-7,0,0"
                       Style="{StaticResource PhoneTextTitle1Style}"
                       Text="{StaticResource IDS_MESSAGE_HISTORY}" />
        </StackPanel>

        <Grid Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <ListBox ItemContainerStyle="{StaticResource message_itemstyle}" ItemsSource="{Binding ItemsOfMessage}" />

            <TextBlock Style="{StaticResource PhoneTextTitle3Style}" 
                       Text="{StaticResource IDS_COMMON_NODATA}" 
                       Visibility="{Binding ItemsOfMessage.Count, Converter={StaticResource NumberEqualsParameterToVisibilityConverter}, ConverterParameter=0}"/>
            
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>

                <TextBlock VerticalAlignment="Center" Style="{StaticResource PhoneTextTitle2Style}">
                    <Run Text="{Binding ItemsOfMessage.Count}" />
                    <Run Text=" / " />
                    <Run Text="{Binding ItemsCount, Mode=OneWay}" />
                </TextBlock>

                <UX:UXPathButton Grid.Row="1"
                                 Grid.Column="1"
                                 Margin="12"
                                 Command="{Binding LoadPreviousCommand,
                                                   Mode=OneWay}"
                                 IconPath="{StaticResource PATH_ICON_DOWN}" />
            </Grid>

        </Grid>
    </Grid>
</phone:PhoneApplicationPage>
